package com.sl.adapter;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.sl.R;
import com.sl.model.ShoppingProduct;

public class ShoppingDetailsActivityAdapter extends BaseAdapter {
	private Context mContext;
	private List<ShoppingProduct> mRecords;
	private LayoutInflater mInflater;
	
	public ShoppingDetailsActivityAdapter(Context context, List<ShoppingProduct> records){
		this.mContext = context;
		this.mRecords = records;
		this.mInflater = LayoutInflater.from(mContext);
	}
	
	@Override
	public int getCount() {
		if(mRecords == null){
			return 0;
		}
		
		return mRecords.size();
	}

	@Override
	public Object getItem(int position) {
		if(mRecords == null){
			return null;
		}
		
		return mRecords.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {	
		ViewHolder holder = null;
		
		holder = new ViewHolder();
		
		convertView = mInflater.inflate(R.layout.shopping_details_item, null);
		
		holder.name = (TextView)convertView.findViewById(R.id.name);
		holder.quantity = (TextView)convertView.findViewById(R.id.quantity);
		
		holder.name.setText(((ShoppingProduct)mRecords.get(position)).getName());
		holder.quantity.setText(String.valueOf(((ShoppingProduct)mRecords.get(position)).getQuantity()));
		
		return convertView;
	}
	
	public final class ViewHolder {
		public TextView name;
		public TextView quantity;
	}
}
